<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Home extends CI_Controller {
    public function __construct() {
            parent::__construct();
            $this->load->model('item', 'item');
    }
    public function index()
    {
        $display = array();
        $q_jenis = $this->db->query('select * from category')->result_array();
        $display['kota'] =$this->item->get_dropdown_kota();
        $display['jenis'] =$this->item->get_dropdown_jenis();
        $display['display']='style="display:anything;"';
        $this->load->view('home', $display);
    }
    function search_processing(){
        $header = array();
        $header['navigation'] = "HOME > HASIL PENCARIAN";
        $header['kota'] =$this->item->get_dropdown_kota();
        $header['jenis'] =$this->item->get_dropdown_jenis();
        $header['display'] = null;
        
        $query = (!empty($_POST['query'])) ? $this->input->post('query') : '';
        $jenis = (!empty($_POST['jenis'])) ? $this->input->post('jenis') : '0';
        $kota = (!empty($_POST['kota'])) ? $this->input->post('kota') : '0';
        
        if(empty($query)){
            redirect(base_url());
        }
            
        $display = array();
        $display['kota'] =$this->item->get_dropdown_kota();
        $display['jenis'] =$this->item->get_dropdown_jenis();
        
        $search_term_esc = AddSlashes($query);
        $where = '';
        if($kota!=0)
            $where .= ' and ID_CITY='.$kota.' ';
        if($jenis!=0){
            $sql = $this->db->query("SELECT * FROM item WHERE NAME LIKE '%$query%'".$where.' and ID_ITEM in 
                (select ID_ITEM from item_cat where ID_CATEGORY='.$jenis.')')->result_array();
        }else    
            $sql = $this->db->query("SELECT * FROM item WHERE NAME LIKE '%$query%'".$where)->result_array();
        $display['query'] = $query;
        $display['item'] = $sql;
        
        $this->load->view('header', $header);
        $this->load->view('search', $display);
        $this->load->view('footer');        
    }
    function contact(){
        $this->load->view('header');
        $this->load->view('contact');
        $this->load->view('footer');        
    }
    function faq(){
        $this->load->view('header');
        $this->load->view('faq');
        $this->load->view('footer');        
    }
    function term(){
        $this->load->view('header');
        $this->load->view('terms');
        $this->load->view('footer');        
    }
    function register(){
        $header = array();
        $header['navigation'] = "HOME > DAFTAR";
        $this->load->view('header', $header);
        $this->load->view('register');
        $this->load->view('footer');        
    }
}
